/*
 * helperfuncs.h
 * CS 3251 Programming Assignment #2
 * Dustin Shiflett
 */ 

#ifndef __HELPERFUNCS__
#define __HELPERFUNCS__

/* print functions for debug mode only */
#define print(x) if (debug) { printf(x); fflush(stdout); }
#define aprint(x,a) if (debug) { printf(x, a); fflush(stdout); }

/* error or non-debug printing */
#define printError(x) printf(x); fflush(stdout);


#define MAX_WINDOW_SIZE     32768 /*Max buffer size to expect (in bytes)*/
#define MAX_BUFFER_SIZE     65536 /*to be safe*/
#define MIN_WINDOW_SIZE     1024  /*Min buffer size to expect (in bytes)*/
#define MAX_RETRY   20  /*# of times to retransmit if we don't get an ACK*/
#define SRTTCONSTANT    .125    /* 0 < a < 1; .125 = 1 / 8 */


/*packet header structures*/
typedef struct {
    unsigned int progID, seqNumber, fileNameLength, maxPacketLength, windowLength;
    char fileName[256];
} initHeader;

typedef struct {
    unsigned int progID, seqNumber;
} regHeader


typedef struct {
    unsigned int progID, nextSeqNumExpected;
} ackPacket


/*unsure about SIGNALs still, so putting this here like example code*/
void sigint();

int createUDPSocket();

void closeSocket(int sock);

int calcRTO(int origRTO, int RTT);
/*
origRTO: Smoothed Round Trip Time is origRTO / 2
RTT: Round Trip Time from the transmission of last packet until receiving the ACK for that packet
Returns the new Retransmission TimeOut
*/

int fileExists(char* fileName)
/*Returns 1 if the filename exists, 0 otherwise*/

#endif
